/*
* Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef OHMW_SA_LOG_H
#define OHMW_SA_LOG_H

#ifdef OHOS_ARCH_LITE
#include "hilog/log.h"
#else
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#endif

#include <unistd.h>

namespace OHOS {
namespace OHMW {
const unsigned int LOG_DOMAIN_ROBOT = 0xD002100; // FIXME

#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)

#define DEFINE_OHMW_LOG_LABEL(name) \
    static constexpr OHOS::HiviewDFX::HiLogLabel OHMW_LOG_LABEL = {LOG_CORE, OHOS::OHMW::LOG_DOMAIN_ROBOT, name};

#define OHMW_LOGF(fmt, ...) \
    (void)OHOS::HiviewDFX::HiLog::Fatal(OHMW_LOG_LABEL, "%{public}d [%{public}s:%{public}d] " fmt, gettid(), FILENAME, \
                                        __LINE__, ##__VA_ARGS__)
#define OHMW_LOGE(fmt, ...) \
    (void)OHOS::HiviewDFX::HiLog::Error(OHMW_LOG_LABEL, "%{public}d [%{public}s:%{public}d] " fmt, gettid(), FILENAME, \
                                        __LINE__, ##__VA_ARGS__)
#define OHMW_LOGW(fmt, ...) \
    (void)OHOS::HiviewDFX::HiLog::Warn(OHMW_LOG_LABEL, "%{public}d [%{public}s:%{public}d] " fmt, gettid(), FILENAME, \
                                        __LINE__, ##__VA_ARGS__)
#define OHMW_LOGI(fmt, ...) \
    (void)OHOS::HiviewDFX::HiLog::Info(OHMW_LOG_LABEL, "%{public}d [%{public}s:%{public}d] " fmt, gettid(), FILENAME, \
                                        __LINE__, ##__VA_ARGS__)
#define OHMW_LOGD(fmt, ...) \
    (void)OHOS::HiviewDFX::HiLog::Debug(OHMW_LOG_LABEL, "%{public}d [%{public}s:%{public}d] " fmt, gettid(), FILENAME, \
                                        __LINE__, ##__VA_ARGS__)
}
}

#endif
